/**
 * col_file
 */
layui.define(['YunjColsTemplet','jquery','yunj'], function (exports) {

    let YunjColsTemplet = layui.YunjColsTemplet;
    let doc = document;
    let $ = layui.jquery;

    class YunjColsTempletFile extends YunjColsTemplet{

        constructor(options) {
            super(options);
        }

        layout(){
            let that=this;
            return `{{# 
                         let file = d.${that.key};
                         if(yunj.isString(file)) file = file.length>0?JSON.parse(file):{};
                         if(!yunj.isObj(file)) file = {};
                     }}
                     {{#  if(!yunj.isEmptyObj(file)){ }}
                         <div class="table-row-file">
                            {{#  let text=file.name+(d.is_export?"（"+file.url+"）":"");  }}
                            <a href="javascript:void(0);" title="点击下载" data-name="{{ file.name }}" data-url="{{ file.url }}">{{ text }}</a>
                         </div>
                     {{#  } }}`;
        }

        defineExtraEventBind(){
            let that=this;

            $(doc).on('click','.table-row-file a',function () {
                let aEl=$(this);
                let name=aEl.data('name');
                let url=aEl.data('url');
                yunj.confirm(`确认下载文件[${name}]？`,null,(idx)=>{
                    if(name.length<=0||url.length<=0) return false;
                    yunj.download({name:name,url:url});
                });
            });
        }

    }

    exports('col_file', YunjColsTempletFile);
});